<?php
/**
 * Created by PhpStorm.
 * User: zcq
 * Date: 2018/12/12
 * Time: 15:14
 */

namespace app\index\model;


use app\common\RedisCache;

class Vote extends BaseModel
{
    const TABLE = 'vote';

    const ENABLE_TRUE = 1;//正常
    const ENABLE_FALSE = 0;//禁止

    const VOTE_TYPE_DAY = 1; //按天
    const VOTE_TYPE_WEEK = 2; //按周
    const VOTE_TYPE_TOTAL = 3; //总数

    const IP_YES = 1; //限制ip
    const IP_NO = 0; //不限制ip;

    const COMMENT_TYPE_BAIDU = 1; //百度审核
    const COMMENT_TYPE_HAND = 2;  //手动审核
    const COMMENT_TYPE_FALSE = 3; //不允许评论

    public static function getVote($id)
    {
        //活动暂时缓存一个月
        $key = 'vote_'.$id;
        $expireTime = 30*24*3600;
        $vote = RedisCache::getInstance()->cache($key);
        if($vote)
            return json_decode($vote,1);

        $vote = self::where('id',$id)->find();
        if($vote){
            RedisCache::getInstance()->cache($key,json_encode($vote,JSON_UNESCAPED_UNICODE),$expireTime);
        }

        return $vote;
    }
}